import Vue from 'vue'
//import ElementUI from 'element-ui'
import ELEMENT from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import $ from 'jquery'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min.js'

import { userInfoAPI } from './api/index'
import {localStorage} from '@/assets/common/localStorage'

import moment from 'moment'

// 之所以把Hls挂载window对象上，是因为当DPlayer.video.type='hls'时，new DPlayer()对象会用到此对象。
window.Hls = require('hls.js')
window.$flv = require('flv.js')
Vue.prototype.$moment = moment

// Vue.use(ElementUI)
Vue.use(ELEMENT)

Vue.config.productionTip = false

// 直接获取用户信息
userInfoAPI.getUserInfo({}, (data) => {
  if (data && data.uid) {
    var purchaseAdminRole = null
    var developRole = null
    var purchaseOperateRole = null
    var purchaseWorkRole = null
    var performanceWorkRole = null
    if (data.roleList) {
      for (let i = 0; i < data.roleList.length; i++) {
        if (data.roleList[i].code === 'purchaseAdminRole') {
          purchaseAdminRole = data.roleList[i]
        } else if (data.roleList[i].code === 'developRole') {
          developRole = data.roleList[i]
        } else if (data.roleList[i].code === 'purchaseOperateRole') {
          purchaseOperateRole = data.roleList[i]
        } else if (data.roleList[i].code === 'purchaseWorkRole') {
          purchaseWorkRole = data.roleList[i]
        } else if (data.roleList[i].code === 'performanceWorkRole') {
          performanceWorkRole = data.roleList[i]
        }
      }
    }
    new Vue({
      data: {
        uid: data.uid,
        username: data.name,
        email: data.email,
        purchaseAdminRole: purchaseAdminRole,
        developRole: developRole,
        purchaseOperateRole: purchaseOperateRole,
        purchaseWorkRole: purchaseWorkRole,
        performanceWorkRole: performanceWorkRole
      },
      el: '#app',
      router,
      template: '<App/>',
      components: { App }
    })
  }
})

/**
 * 在请求后台接口时再进行check login
 */

/* new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
}) */
